﻿using Irony.Parsing;
using NMF.Languages.AnyText.ClassConstruction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NMF.Languages.AnyText
{
    public abstract class DataTypeTerminal : TypedNonTerminal
    {
        public DataTypeTerminal(string name)
            : base(name)
        {}

        public abstract BnfExpression CreateRule(AnyTextGrammar grammar);

        public override void PreInit(GrammarData grammarData)
        {
            Rule = CreateRule(grammarData.Grammar as AnyTextGrammar);
        }

        public virtual object GetValue(ParseTreeNode node)
        {
            return node.ChildNodes[0].Token.Value;
        }

        public override bool IsComplexType { get { return true; } }
        public override bool IsDataType { get { return false; } }
    }
    
    public abstract class DataTypeTerminal<T> : DataTypeTerminal
        where T : DataType
    {
        protected DataTypeTerminal(string name, T type, BnfExpression rule)
            : base(name)
        {
            this.Rule = rule;
            this.DataType = type;
        }

        protected DataTypeTerminal(string name, T type)
            : base(name)
        {
            this.DataType = type;
        }

        public abstract DataTypeTerminal<T> CreateCustom();

        public T DataType { get; private set; }

        public override TypeReference Type
        {
            get { return DataType; }
        }
    }
}
